package com.sig.formes;

public class Point {

	public float x,y = 0f;
	
	public static float minX = Float.MAX_VALUE;
	public static float minY = Float.MAX_VALUE;
	public static float maxX = Float.MIN_VALUE;
	public static float maxY = Float.MIN_VALUE;
	
	public static void testerMaxX(float x){
		if(x<Point.minX)
			Point.minX = x;
		if(x>Point.maxX)
			Point.maxX = x;
	}
	
	public static void testerMaxY(float y){
		if(y<Point.minY)
			Point.minY = y;
		if(y>Point.maxY)
			Point.maxY = y;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(x);
		result = prime * result + Float.floatToIntBits(y);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Point other = (Point) obj;
		if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
			return false;
		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
			return false;
		return true;
	}

	public static void testerMaxs(float x, float y){
		testerMaxX(x);
		testerMaxY(y);
	}
	
	
	public Point(){
	}
	public Point(float px,float py,boolean earcutting){
		x = px;
		y = py;
		
		if(!earcutting)
			testerMaxs(x, y);
	}
	public Point(float px,float py){
		this(px,py,false);
		testerMaxs(x, y);
	}
	public float distanceTo(Point q) {
		Point p = this;
		float dx = p.x - q.x;
		float dy = p.y - q.y;
		return (float)Math.sqrt(dx*dx + dy*dy);
	}
	public String toString(){
		return "Point(x: "+x+" ; y: "+y+")";
	}
	
	public float getX() {
		return x;
	}
	
	public void setX(float x) {
		this.x = x;
		testerMaxX(x);
	}
	public float getY() {
		return y;
	}
	public void setY(float y) {
		this.y = y;
		testerMaxY(y);
	}
	
	
	public float getOpenGLX() {
		return getX();
	}
	public float getOpenGLY() {
		return getY();
	}
	
}
